LassoScript Utility
Basics Browse Detail

[Net->Connect]

Tag Link [Net->Connect] Category Networking
Type Member Source Available Yes
Support Preferred Version 7.0
Change Unchanged Data Source Any
Output Type Integer Security None
Implementation LCAPI Sets Lasso 8.5, Lasso 8.0, Lasso 7.0

Description

[Net->Connect] is used to establish an outgoing TCP connection with a remote host on a specific port. Once a connection is established data can be read from the connection using [Net->Read] or written to the connection using [Net->Write].

[Net->Connect] returns [Net_ConnectOK] if the connection was made successfully or [Net_ConnectInProgress] if the object already has an open connection.

Syntax

<?LassoScript
Variable: 'Connection' = (Net);
$Connection->(Connect: 'www.example.com', 80);
Variable: 'Data' = $Connection->(Read: 32768);
...
$Connection->Close;
?>

Parameters

Required Parameters
Host Name The DNS host name or IP address of the remote host.
Port The port number to connect to.

Examples

To connect to a remote server using TCP:

Use the [Net] type and its member tags to establish a TCP connection. The following example opens a blocking TCP connection to the Web server running on an example server and fetches the root document. The result will be an HTML page.

[Variable: 'myConnection' = (Net)]
[$myConnection->(SetBlocking: True)]
[Var: 'Result' = $myConnection->(Connect: 'www.example.com', 80)]
[Fail_If: $Result != Net_ConnectOK, (-1), 'TCP Error']
[Variable: 'Result' = $myConnection->(Write: 'GET / HTTP/1.0\r\n\r\n')]
[Variable: 'Output' = $myConnection->(Read: 32768)]
[$myConnection->(Close)]
[Output: $Output]

<html><head><title>HTML Document</title></head>>body> ...